package client;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.text.DecimalFormat;
import java.util.Random;

public class DateThread extends Thread {
	private Socket socket;
	private String mac;

	public DateThread(Socket socket,String mac) {
		super();
		this.socket = socket;
		this.mac=mac;
	}

	public void run() {
		try {

			try {
				PrintWriter out = new PrintWriter(new OutputStreamWriter(socket
						.getOutputStream()), true);
				Random rnd = new Random();

				DecimalFormat df = new DecimalFormat("0.0");
				String paramph = null;
				String paramorp = null;
				String paramtem = null;
				String paramec = null;
				String paramope = null;
				String paramclo = null;
				String mac=this.getMac();   
				int seq;
				for (int i = 1; i < 0; i++) {
					seq=i;
					paramph="ph="+df.format(Math.random() * 14);
					paramorp="orp="+((Double)(Math.random() * 2000)).intValue();
					paramtem="tem="+df.format(Math.random() * 100);
					paramec="clo="+df.format(Math.random() * 20);
					paramope="oclo="+((Double)(Math.random() * 400)).intValue();
					paramclo="cclo="+((Double)(Math.random() * 10000)).intValue();
					String paramesil="esil="+new java.util.Random().nextInt(3);
					String paramec1="ec1="+((Double)(Math.random() * 10000)).intValue();
					String paramec2="ec2="+((Double)(Math.random() * 10000)).intValue();
					//System.out.println(mac+"&"+seq+"&"+paramph+""+"&"+paramorp+""+"&"+paramtem+""+"&"+paramec+""+"&"+paramope+"&"+paramclo);
					out.println(mac+"&"+seq+"&"+paramph+""+"&"+paramorp+""+"&"+paramtem+""+"&"+paramec+""+"&"+paramope+
							"&"+paramclo+"&"+paramesil+"&"+paramec1+"&"+paramec2);
					try {
						Thread.sleep(1000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} finally {
				socket.close();
			}

		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}// TCPServer.SERVERIP
		catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public String getMac() {
		return mac;
	}

	public void setMac(String mac) {
		this.mac = mac;
	}
	
}
